package com.passer.web.travel.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.passer.common.annotation.Log;
import com.passer.common.enums.BusinessType;
import com.passer.web.travel.domain.TImages;
import com.passer.web.travel.service.ITImagesService;
import com.passer.common.core.controller.BaseController;
import com.passer.common.core.domain.AjaxResult;
import com.passer.common.utils.poi.ExcelUtil;
import com.passer.common.core.page.TableDataInfo;

/**
 * 图片信息Controller
 *
 * @author passer
 * @date 2021-11-23
 */
@Controller
@RequestMapping("/travel/images")
public class TImagesController extends BaseController
{
    private String prefix = "travel/images";

    @Autowired
    private ITImagesService tImagesService;

    @RequiresPermissions("travel:images:view")
    @GetMapping()
    public String images()
    {
        return prefix + "/images";
    }

    /**
     * 查询图片信息列表
     */
    @RequiresPermissions("travel:images:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TImages tImages)
    {
        startPage();
        List<TImages> list = tImagesService.selectTImagesList(tImages);
        return getDataTable(list);
    }

    /**
     * 导出图片信息列表
     */
    @RequiresPermissions("travel:images:export")
    @Log(title = "图片信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TImages tImages)
    {
        List<TImages> list = tImagesService.selectTImagesList(tImages);
        ExcelUtil<TImages> util = new ExcelUtil<TImages>(TImages.class);
        return util.exportExcel(list, "图片信息数据");
    }

    /**
     * 新增图片信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图片信息
     */
    @RequiresPermissions("travel:images:add")
    @Log(title = "图片信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TImages tImages)
    {
        return toAjax(tImagesService.insertTImages(tImages));
    }

    /**
     * 修改图片信息
     */
    @GetMapping("/edit/{sid}")
    public String edit(@PathVariable("sid") Long sid, ModelMap mmap)
    {
        TImages tImages = tImagesService.selectTImagesById(sid);
        mmap.put("tImages", tImages);
        return prefix + "/edit";
    }

    /**
     * 修改保存图片信息
     */
    @RequiresPermissions("travel:images:edit")
    @Log(title = "图片信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TImages tImages)
    {
        return toAjax(tImagesService.updateTImages(tImages));
    }

    /**
     * 删除图片信息
     */
    @RequiresPermissions("travel:images:remove")
    @Log(title = "图片信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tImagesService.deleteTImagesByIds(ids));
    }
}
